//
//  UIButton+Extension.swift
//  weibo10
//
//  Created by 猎人 on 15/10/15.
//  Copyright © 2015年 hunter. All rights reserved.
//

import UIKit
// MARK: - <#Description#>
extension UIButton {
    /// 便利构造函数
    ///
    /// - parameter imageName:     图片名称
    /// - parameter backImageName: 背景图片名称
    ///
    /// - returns: UIButton
    convenience init (imageName: String, backImageName: String) {
        self.init()
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        // 自动调整大小
        sizeToFit()
        
    }
    /// 遍历构造函数
    ///
    /// - parameter title:     title
    /// - parameter color:     color
    /// - parameter imageName: 背景图片
    ///
    /// - returns: UIButton
    convenience init (title: String, color: UIColor, imageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setBackgroundImage(UIImage(named: imageName), forState: .Normal)
    }
    
    /// 便利构造函数
    ///
    /// - parameter title:     title
    /// - parameter color:     color
    /// - parameter fontSize:  字体大小
    /// - parameter imageName: 图像名称
    ///
    /// - returns: UIButton
    convenience init(title: String, fontSize: CGFloat, color: UIColor, imageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setImage(UIImage(named: imageName), forState: .Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
    }

}